package keyword

import (
	"encoding/json"
	"kop/modules/configuration/client"
	"kop/util/log"
	"strings"
)

var KeyWords arr

func init() {

	var b = client.Load("BadWordsTemplate")
	if err := json.Unmarshal(b, &KeyWords); err != nil {
		panic(err)
	}

	log.Info("Load BadWordsTemplate.json success.")

}

type arr []string

func (a arr) Replace(s string) string {

	for _, v := range a {

		var newStr = make([]string, len([]rune(v)))
		for k := range newStr {
			newStr[k] = "*"
		}

		s = strings.Replace(s, v, strings.Join(newStr, ""), -1)
	}

	return s
}
